import request from '@/utils/request.js'
import {useTokenStore} from "@/stores/token.js";
//注册接口的函数

export const userRegisterService=(registerData)=>{
    const params=new URLSearchParams()
    for(let key in registerData){
        params.append(key,registerData[key])
    }
    return request.post('/user/register',params)
}
//登录接口的函数
export const userLoginService=(loginData)=>{
    const params=new URLSearchParams();
    for(let key in loginData){
        params.append(key,loginData[key])
    }
    return request.post('/user/login',params)
}

export const userInfoService=()=>{
    const tokenStore=useTokenStore();
    return request.get('/user/userinfo',{headers:{'Authorization':tokenStore.token}})
}

export const userInfoUpdateService=(userinfoData)=>{
    return request.put('/user/update',userinfoData)
}

export const userAvatarUpdateService=(avatarUrl)=>{
    const params=new URLSearchParams(avatarUrl)
    params.append('avatarurl',avatarUrl)
    return request.patch('/user/updateavatar',params)
}